<?php

Function show_groups($start, $limit)
{
  	$table_groups = $_SESSION['prefix']."groups";
	$req = dbquery("SELECT gid,title,description FROM $table_groups WHERE 1 ORDER BY gid ASC LIMIT $start,$limit");
	if (@mysql_num_rows($req) == 0)
		return (-1);
   
	while ($line = @mysql_fetch_array($req))
    {
			Print("
				<thead>
				<tr>
					<td align=center><font color=green>$line[gid]</font></td>
					<td align=left><font color=darkblue><b>$line[title]</b></font></td>
					<td align=left><font color=#4B4B4B>$line[description]</font></td>
					<td align=center>
						<a href=\"ipage.php?height=230&act=group&sub=infos&gid=$line[gid]\" class=\"thickbox\" title=\"<font color=royalblue><b>Informations groupe</b></font>\"><img src=\"$_SESSION[current_path]/images/group.png\" width=16 height=16 title=\"Informations sur le groupe $line[title]\"></a>
			");
			if (($line['gid'] != 1) && ($line['gid'] != 2))
			{
				Print("
					' 
					<a href=\"ipage.php?height=370&act=group&sub=edit&gid=$line[gid]\" class=\"thickbox\" title=\"<font color=royalblue><b>Edition groupe</b></font>\"><img src=\"$_SESSION[current_path]/images/group_edit.png\" width=16 height=16 title=\"Modifier le groupe $line[title]\"></a> ' 
					<a href=\"ipage.php?height=200&act=group&sub=delete&gid=$line[gid]\" class=\"thickbox\" title=\"<font color=red><b>Suppression groupe</b></font>\"><img src=\"$_SESSION[current_path]/images/group_delete.png\" width=16 height=16 title=\"Supprimer le groupe $line[title]\"></a>
				");
			}
			
			if ((($line['gid'] == 1) || ($line['gid'] == 2)) && (is_root(@$_SESSION['login'])))
			{
				Print("
					' 
					<a href=\"ipage.php?height=370&act=group&sub=edit&gid=$line[gid]\" class=\"thickbox\" title=\"<font color=royalblue><b>Edition groupe</b></font>\"><img src=\"$_SESSION[current_path]/images/group_edit.png\" width=16 height=16 title=\"Modifier le groupe $line[title]\"></a> ' 
					<a href=\"ipage.php?height=200&act=group&sub=delete&gid=$line[gid]\" class=\"thickbox\" title=\"<font color=red><b>Suppression groupe</b></font>\"><img src=\"$_SESSION[current_path]/images/group_delete.png\" width=16 height=16 title=\"Supprimer le groupe $line[title]\"></a>
				");
			}
				
			Print("						
					</td>
				</tr>
				</thead>
			");
	}
	return;
}

Function show_group_new()
{
	Print("
		<div id=\"box\">
			<form action=\"users.php\" method=POST>
			<h3>Nom: <input type=text name=\"name\"></h3>
			<input type=hidden name=\"act\" value=\"new_group\">
			<table cellpadding=0 cellspacing=0 border=0 width=100%>
				<tr>
					<td width=30% valign=top><b><font color=royalblue>Description:</font></b></td>
					<td><textarea cols=40 rows=5 name=\"description\"></textarea></td>
				</tr>
				<tr>
					<td></td>
					<td></td>
					<td align=right><input type=submit value=\"Ajouter\"></td>
				</tr>
			</table>
		</form>
		</div>
	");
	return;
}

Function show_group_infos($gid)
{
	$group_infos = get_group_infos($gid);
	$group_users = get_group_users($gid);
	Print("T: $group_users");
	
	Print("
		<div id=\"box\">
			<h3>$group_infos[title]</h3>
			<table cellpadding=0 cellspacing=0 border=0 width=100%>
				<tr>
					<td width=30%><b><font color=royalblue>GID:</font></b></td>
					<td><font color=#4B4B4B>$gid</font></td>
				</tr>
				<tr>
					<td valign=top><b><font color=royalblue>Description:</font></b></td>
					<td><font color=#4B4B4B>$group_infos[description]</font></td>
				</tr>
			</table>
			<hr color=#4B4B4B>
			<table cellpadding=0 cellspacing=0 border=0 width=100%>
				<tr>
					<td width=30% valign=top><b><font color=royalblue>Utilisateurs du groupe:</font></b></td>
					<td>");
						show_list($group_users, "users");
					Print("</td>
				</tr>
			</table>
		</div>
	");
	return;
}

Function show_group_edit($gid)
{
	$group_infos = get_group_infos($gid);
	$group_users = get_group_users($gid);
	
	Print("
		<div id=\"box\">
			<form action=\"users.php\" method=POST>
			<h3>Nom: <input type=text name=\"name\" value=\"$group_infos[title]\"></h3>
			<input type=hidden name=\"act\" value=\"edit_group\">
			<input type=hidden name=\"gid\" value=\"$gid\">
			<table cellpadding=0 cellspacing=0 border=0 width=100%>
				<tr>
					<td width=30%><b><font color=royalblue>GID:</font></b></td>
					<td><font color=#4B4B4B>$gid</font></td>
				</tr>
				<tr>
					<td valign=top><b><font color=royalblue>Description:</font></b></td>
					<td><textarea cols=40 rows=5 name=\"description\">$group_infos[description]</textarea></td>
				</tr>
			</table>
			<table cellpadding=0 cellspacing=0 border=0 width=100%>
				<tr>
					<td align=right><input type=submit value=\"Modifier\"></td>
				</tr>
			</table>
			</form>
			<hr color=#4B4B4B>
			<form action=\"users.php\" method=POST>
			<input type=hidden name=\"act\" value=\"edit_delete_group\">
			<input type=hidden name=\"gid\" value=\"$gid\">
			<table cellpadding=0 cellspacing=0 border=0 width=100%>
				<tr>
					<td valign=top width=30%><b><font color=royalblue>Supprimer un/des utilisateur(s) du groupe:</font></b></td>
					<td width=30%>");
						show_list($group_users, "users");
					Print("</td>
					<td align=left><input type=submit value=\"Supprimer\"></td>
				</tr>
			</table>
			</form>
		</div>
	");
	return;
}

Function show_group_delete($gid)
{
	$group_infos = get_group_infos($gid);
	
	Print("
		<div id=\"box\">
			<h3>
			<table border=0>
				<tr>
					<td width=40><img src=\"$_SESSION[path_images]/large/delete_1.png\" width=40 height=40></td>
					<td><font size=3>Supprimer le groupe $group_infos[title]</font></td>
				</tr>
			</table>
			</h3>
			<center>
				<br>
				<font color=\"red\"><b>Voulez vous continuer ?</b></font>
				<br>
				<table border=0 width=100%>
					<tr>
						<td width=50% align=right>
							<form action=\"users.php\" method=POST>
								<table>
									<tr>
										<td align=right><input type=submit value=\"Annuler\"></td>
									</tr>
								</table>
							</form>
						</td>
						<td>
							<form action=\"users.php\" method=POST>
							<input type=hidden name=\"act\" value=\"delete_group\">
							<input type=hidden name=\"gid\" value=\"$gid\">
							<table>
								<tr>
									<td><input type=submit value=\"Supprimer\"></td>
								</tr>
							</table>
							</form>
						</td>
					</tr>
				</table>
			</center>
		</div>
	");
	return;
}

Function show_list($list, $name)
{
	imports ("odt_frm_php.users");	
	
	if ($name == "users")
		$nname = "utilisateur";
	else
		$nname = "groupe";
		
	if ($list == -1)
	{
		Print("<font color=red><b>Aucun $nname disponible !</b></font>");
		return;
	}
	
  $nb_list = count($list);
  $i = 0;
  
  if ($name == "groups")
		Print("<select name=\"groups[]\" multiple size=5>");
	elseif ($name == "users")
		Print("<select name=\"users[]\" multiple size=5>");
  
  while ($i < $nb_list)
  {
		if ($name == "groups")
			$id = get_gid($list[$i]);
		elseif ($name == "users")
			$id = get_uid($list[$i]);
			
    Print("<option value=\"$id\">$list[$i]</option>");
    $i++;
  }
  Print("</select>");
  return;
}

Function show_user_select_groups($groups)
{
	$nb_groups = count($groups);
	$i = 0;
	Print("<select>");
	while ($i < $nb_groups)
	{
		Print("<option>$groups[$i]</option>");
		$i++;
	}
	Print("</select>");
	return;
}

Function show_select_groups($gids, $selected=FALSE)
{
	$nb_groups = count($gids);
	$i = 0;
	Print("<select name=\"groups\">");
	if ($selected != FALSE)
		Print("<option value=\"-\"></option>");
	while ($i < $nb_groups)
	{
		$group = get_group($gids[$i]);
		Print("<option value=\"$gids[$i]\">$group</option>");
		$i++;
	}
	Print("</select>");
	return;
}

?>